﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApp.Extensions;
using WebApp.Models;

namespace WebApp.Controllers
{
    public partial class SetupController : Controller
    {
        public virtual ActionResult Index()
        {
            return View();
        }

        public virtual ActionResult ENT_Attivita_LST()
        {
            var entities = new Entities();
            var items = entities.ENT_Attivita;
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult ENT_Attivita_SAV(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Attivita.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Attivita.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("ENT_Attivita_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult ENT_Attivita_INS()
        {
            var entities = new Entities();
            var item = new ENT_Attivita();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                entities.ENT_Attivita.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("ENT_Attivita_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult ENT_Attivita_DEL(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Attivita.Where(x => x.Guid == x_guid).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("ENT_Attivita_LST");
        }

        public virtual ActionResult CAM_LST()
        {
            var entities = new Entities();
            var items = entities.ENT_Cameriere;
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult CAM_SAV(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Cameriere.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Cameriere.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("CAM_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult CAM_INS()
        {
            var entities = new Entities();
            var item = new ENT_Cameriere();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                entities.ENT_Cameriere.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("CAM_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult CAM_DEL(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Cameriere.Where(x => x.Guid == x_guid).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("CAM_LST");
        }

        public virtual ActionResult CEN_LST()
        {
            var entities = new Entities();
            var items = entities.ENT_Centro;
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult CEN_SAV(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Centro.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Centro.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("CEN_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult CEN_INS()
        {
            var entities = new Entities();
            var item = new ENT_Centro();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                entities.ENT_Centro.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("CEN_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult CEN_DEL(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Centro.Where(x => x.Guid == x_guid).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("CEN_LST");
        }

        public virtual ActionResult ING_LST()
        {
            var entities = new Entities();
            var items = entities.ENT_Ingrediente.OrderBy(x => x.Nome);
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult ING_SAV(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Ingrediente.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Ingrediente.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("ING_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult ING_INS()
        {
            var entities = new Entities();
            var item = new ENT_Ingrediente();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                entities.ENT_Ingrediente.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("ING_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult ING_DEL(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Ingrediente.Where(x => x.Guid == x_guid).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("ING_LST");
        }

        public virtual ActionResult STA_LST()
        {
            var entities = new Entities();
            var items = entities.ENT_Stampante;
            return View(items);
        }

        public virtual ActionResult PIA_LST()
        {
            var entities = new Entities();
            var items = entities.ENT_Piatto;
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult PIA_SAV(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Piatto.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Piatto.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("PIA_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult PIA_INS()
        {
            var entities = new Entities();
            var item = new ENT_Piatto();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                entities.ENT_Piatto.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("PIA_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult PIA_DEL(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Piatto.Where(x => x.Guid == x_guid).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("PIA_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult STA_SAV(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Stampante.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Stampante.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("STA_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult STA_INS()
        {
            var entities = new Entities();
            var item = new ENT_Stampante();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                entities.ENT_Stampante.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("STA_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult STA_DEL(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Stampante.Where(x => x.Guid == x_guid).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("STA_LST");
        }

        public virtual ActionResult SAL_LST()
        {
            var entities = new Entities();
            var items = entities.ENT_Sala;
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult SAL_SAV(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Sala.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Sala.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("SAL_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult SAL_INS()
        {
            var entities = new Entities();
            var item = new ENT_Sala();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                entities.ENT_Sala.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("SAL_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult SAL_DEL(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Sala.Where(x => x.Guid == x_guid).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("SAL_LST");
        }

        public virtual ActionResult CLI_LST()
        {
            var entities = new Entities();
            var items = entities.ENT_Cliente;
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult CLI_SAV(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Cliente.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Cliente.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("CLI_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult CLI_INS()
        {
            var entities = new Entities();
            var item = new ENT_Cliente();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                entities.ENT_Cliente.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("CLI_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult CLI_DEL(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Cliente.Where(x => x.Guid == x_guid).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("CLI_LST");
        }

        public virtual ActionResult PIA_ING_LST(String f0)
        {
            var entities = new Entities();
            Guid x_guid = new Guid(f0);
            var fml = entities.ENT_Piatto.Where(x => x.Guid == x_guid).Single().Famiglia.ToString();
            ViewData["ptt"] = f0;
            ViewData["fml"] = fml;
            var items = entities.REL_Piatto_Ingrediente.Where(x => x.Piatto == x_guid);
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult PIA_ING_SAV(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.REL_Piatto_Ingrediente.Where(x => x.Guid == x_id).Single();
            if (TryUpdateModel(item))
            {
                entities.REL_Piatto_Ingrediente.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("PIA_ING_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult PIA_ING_INS(string f0)
        {
            var entities = new Entities();
            var item = new REL_Piatto_Ingrediente();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                item.Piatto = new Guid(f0);
                entities.REL_Piatto_Ingrediente.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("PIA_ING_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult PIA_ING_DEL(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.REL_Piatto_Ingrediente.Where(x => x.Guid == x_id).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("PIA_ING_LST", new { f0 = f0 });
        }

        public virtual ActionResult STA_CEN_LST(String f0)
        {
            var entities = new Entities();
            Guid x_guid = new Guid(f0);
            ViewData["stm"] = f0;
            var items = entities.ENT_Centro.Where(x => x.Stampante == x_guid);
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult STA_CEN_SAV(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.ENT_Centro.Where(x => x.Guid == x_id).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Centro.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("STA_CEN_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult STA_CEN_INS(string f0)
        {
            var entities = new Entities();
            var item = new ENT_Centro();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                item.Stampante = new Guid(f0);
                entities.ENT_Centro.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("STA_CEN_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult STA_CEN_DEL(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.ENT_Centro.Where(x => x.Guid == x_id).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("STA_CEN_LST", new { f0 = f0 });
        }

        public virtual ActionResult SAL_TAV_LST(String f0)
        {
            var entities = new Entities();
            Guid x_guid = new Guid(f0);
            ViewData["sla"] = f0;
            var items = entities.ENT_Tavolo.Where(x => x.Sala == x_guid);
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult SAL_TAV_SAV(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.ENT_Tavolo.Where(x => x.Guid == x_id).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Tavolo.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("SAL_TAV_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult SAL_TAV_INS(string f0)
        {
            var entities = new Entities();
            var item = new ENT_Tavolo();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                item.Sala = new Guid(f0);
                entities.ENT_Tavolo.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("SAL_TAV_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult SAL_TAV_DEL(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.ENT_Tavolo.Where(x => x.Guid == x_id).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("SAL_TAV_LST", new { f0 = f0 });
        }

        public virtual ActionResult FAM_LST()
        {
            var entities = new Entities();
            var items = entities.ENT_Gruppo;
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult FAM_SAV(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Gruppo.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Gruppo.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("FAM_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult FAM_INS()
        {
            var entities = new Entities();
            var item = new ENT_Gruppo();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                entities.ENT_Gruppo.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("FAM_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult FAM_DEL(string id)
        {
            var entities = new Entities();
            var x_guid = new Guid(id);
            var item = entities.ENT_Gruppo.Where(x => x.Guid == x_guid).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("FAM_LST");
        }

        public virtual ActionResult FAM_PIA_LST(String f0)
        {
            var entities = new Entities();
            ViewData["fml"] = f0;
            Guid x_guid = new Guid(f0);
            var items = entities.ENT_Piatto.Where(x => x.Famiglia == x_guid);
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult FAM_PIA_SAV(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.ENT_Piatto.Where(x => x.Guid == x_id).Single();
            if (TryUpdateModel(item))
            {
                entities.ENT_Piatto.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("FAM_PIA_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult FAM_PIA_INS(string f0)
        {
            var entities = new Entities();
            var item = new ENT_Piatto();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                item.Famiglia = new Guid(f0);
                entities.ENT_Piatto.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("FAM_PIA_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult FAM_PIA_DEL(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.ENT_Piatto.Where(x => x.Guid == x_id).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("FAM_PIA_LST", new { f0 = f0 });
        }

        public virtual ActionResult FAM_ING_LST(String f0)
        {
            var entities = new Entities();
            ViewData["f0"] = f0;
            Guid x_guid = new Guid(f0);
            var items = entities.REL_Gruppo_Ingrediente.Where(x => x.Famiglia == x_guid);
            return View(items);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult FAM_ING_SAV(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.REL_Gruppo_Ingrediente.Where(x => x.Guid == x_id).Single();
            if (TryUpdateModel(item))
            {
                entities.REL_Gruppo_Ingrediente.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Modified;
                entities.SaveChanges();
            }
            return RedirectToAction("FAM_ING_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult FAM_ING_INS(string f0)
        {
            var entities = new Entities();
            var item = new REL_Gruppo_Ingrediente();
            if (TryUpdateModel(item))
            {
                item.Guid = Guid.NewGuid();
                item.Famiglia = new Guid(f0);
                entities.REL_Gruppo_Ingrediente.Attach(item);
                entities.Entry(item).State = System.Data.EntityState.Added;
                entities.SaveChanges();
            }
            return RedirectToAction("FAM_ING_LST", new { f0 = f0 });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult FAM_ING_DEL(string f0, string id)
        {
            var entities = new Entities();
            var x_id = new Guid(id);
            var item = entities.REL_Gruppo_Ingrediente.Where(x => x.Guid == x_id).Single();
            entities.Entry(item).State = System.Data.EntityState.Deleted;
            entities.SaveChanges();
            return RedirectToAction("FAM_ING_LST", new { f0 = f0 });
        }
    }
}
